package qt.service.impl;

import com.github.stuxuhai.jpinyin.PinyinHelper;
import ht.dao.*;
import ht.domain.Mlx;
import ht.domain.Page;
import ht.domain.Ssxmxx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import qt.dao.CzglgxDao;
import qt.dao.LskzmdygxDao;
import qt.dao.SskzmdygxDao;
import qt.dao.StationDao;
import qt.domain.*;
import qt.service.StationSer;
import utils.StcdUtils;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by charmyyy on 2017/10/22.
 */
@Service
public class StationSerImpl implements StationSer {
    @Resource(name = "stationDao")
    private StationDao stationDao;
    @Resource(name = "lskzmdygxDao")
    private LskzmdygxDao lskzmdygxDao;
    @Resource(name = "czglgxDao")
    private CzglgxDao czglgxDao;

    @Resource(name = "lyxxDao")
    private LyxxDao lyxxDao;

    @Resource(name = "xzqhxxDao")
    private XzqhxxDao xzqhxxDao;

    @Resource(name = "sxxxDao")
    private SxxxDao sxxxDao;

    @Resource(name = "czdjxxDao")
    private CzdjxxDao czdjxxDao;

    @Resource(name = "czflxxDao")
    private CzflxxDao czflxxDao;

    @Resource(name = "ssxmxxDao")
    private SsxmxxDao ssxmxxDao;

    @Resource(name = "czlxxxDao")
    private CzlxxxDao czlxxxDao;
    @Resource(name = "hlxxDao")
    private HlxxDao hlxxDao;

    @Resource(name = "gldwDao")
    private GldwDao gldwDao;

    @Resource(name = "sskzmdygxDao")
    private SskzmdygxDao sskzmdygxDao;

    @Resource(name = "mlxDao")
    private MlxDao mlxDao;

    @Resource(name = "relationDao")
    private RelationDao relationDao;

    public DataTable<StationShow> getDataTableStation(int draw, int start, int limit) {
        List<Station> list = stationDao.getPageStation(start, limit);
        List<StationShow> list_show = new ArrayList<StationShow>();
        fill(list,list_show);
        DataTable<StationShow> dt = new DataTable<StationShow>();
        dt.setRecordsTotal(stationDao.getStationCount());
        dt.setRecordsFiltered(stationDao.getStationCount());
        dt.setDraw(draw);
        dt.setData(list_show);
        return dt;
    }

    public DataTable<StationShow> getDataTableStationByAddvcd(int draw, int start, int limit, String addvcd) {
        List<Station> list = stationDao.getAllStationByAddvcd(start, limit,addvcd);
        List<StationShow> list_show = new ArrayList<StationShow>();
        fill(list,list_show);
        DataTable<StationShow> dt = new DataTable<StationShow>();
        dt.setRecordsTotal(stationDao.getAllStationByAddvcdCount(addvcd));
        dt.setRecordsFiltered(stationDao.getAllStationByAddvcdCount(addvcd));
        dt.setDraw(draw);
        dt.setData(list_show);
        return dt;
    }

    public DataTable<StationShow> getDataTableStationByGldw(int draw, int start, int limit, String admagcd){
        List<Station> list = stationDao.getAllStationByAdmagcd(start, limit,admagcd);
        List<StationShow> list_show = new ArrayList<StationShow>();
        fill(list,list_show);
        DataTable<StationShow> dt = new DataTable<StationShow>();
        dt.setRecordsTotal(stationDao.getAllStationByAdmagcdCount(admagcd));
        dt.setRecordsFiltered(stationDao.getAllStationByAdmagcdCount(admagcd));
        dt.setDraw(draw);
        dt.setData(list_show);
        return dt;
    }

    public DataTable<StationShow> getDataTableStationByNmOrId(int draw, int start, int limit, String nmOrid) {
        List<Station> list = stationDao.getAllStationByNmOrId(start, limit,nmOrid);
        List<StationShow> list_show = new ArrayList<StationShow>();
        fill(list,list_show);
        DataTable<StationShow> dt = new DataTable<StationShow>();
        dt.setRecordsTotal(stationDao.getAllStationByNmOrIdCount(nmOrid));
        dt.setRecordsFiltered(stationDao.getAllStationByNmOrIdCount(nmOrid));
        dt.setDraw(draw);
        dt.setData(list_show);
        return dt;
    }

    public StationShow getStation(String stcd) {
        Station s = stationDao.getStation(stcd);
        StationShow ss = new StationShow(s,
                s.getStgrdcd()==null||s.getStgrdcd().equals("")?"":czdjxxDao.getCzdjxx(s.getStgrdcd()).getStgrd(),
                s.getStclcd()==null||s.getStclcd().equals("")?"":czflxxDao.getCzflxx(s.getStclcd()).getStcl(),
                s.getSttpcd()==null||s.getSttpcd().equals("")?"":czlxxxDao.getCzlxxx(s.getSttpcd()).getSttp(),
                s.getAdmagcd()==null||s.getAdmagcd().equals("")?"":gldwDao.getGldw(s.getAdmagcd()).getAdmag(),
                s.getRvcd()==null||s.getRvcd().equals("")?"":hlxxDao.getHlxx(s.getRvcd()).getRvnm(),
                s.getBscd()==null||s.getBscd().equals("")?"":lyxxDao.getLymc(s.getBscd()).getBsnm(),
                "",//多个测验项目要拆分
                s.getHncd()==null||s.getHncd().equals("")?"":sxxxDao.getSxxx(s.getHncd()).getHnnm(),
                s.getAddvcd()==null||s.getAddvcd().equals("")?"":xzqhxxDao.getXzqhxx(s.getAddvcd()).getAddvnm()
        );
        if(s.getObitcd()!=null&&!s.getObitcd().equals("")){
            String obitcd = s.getObitcd();
            String res = "";
            for(int i=0;i<obitcd.length();i++){
                res = res + ssxmxxDao.getSsxmxx(obitcd.charAt(i)+"").getObitnm()+"、";
            }
            ss.setObitnm(res.substring(0,res.length()-1));
        }
        return ss;
    }

    public List<Station> getAllStationIdAndNm(){
        return stationDao.getStationIdAndNm();
    }

    public int getLastStationCountByAddvcd(String addvcd){
        String count = stationDao.getLastStcdByAddvcd(addvcd);
        if(count == null || count.length()<=0){
            return 0;
        }else{
            return Integer.valueOf(count.substring(5,9));
        }
        //return stationDao.getAllStationByAddvcdCount(addvcd);
    }

    public int addStation(Station h) {
        //拼音设置
         h.setSzm(PinyinHelper.getShortPinyin(h.getStnm()));
        return stationDao.addStation(h);
    }

    public int upptStation(Station h) {
        return stationDao.upptStation(h);
    }

    public int deleStation(String stcd) {
        return stationDao.deleStation(stcd);
    }

    public List<Station> getAllStation() {
        return stationDao.getAllStation();
    }

    public List<Station> getStationByAddvcd(String stcd) {
        return stationDao.getStationByAddvcd(stcd);
    }

    public List<Station> getStationByGldw(String gldw) {
        return stationDao.getStationByGldw(gldw);
    }

    public List<CheckBox> getScxmCheckBoxForAdd(){
        List<Ssxmxx> ssxmxx = ssxmxxDao.getAllSsxmxx();
        List<CheckBox> checkBoxes = new ArrayList<CheckBox>();
        for(Ssxmxx s : ssxmxx){
            CheckBox cb = new CheckBox();
            cb.setBoxLabel(s.getObitnm());
            cb.setInputValue(s.getObitcd());
            checkBoxes.add(cb);
        }
        return checkBoxes;
    }

    public List<CheckBox> getScxmCheckBoxForUpdate(String stcd){
        List<Ssxmxx> ssxmxx = ssxmxxDao.getAllSsxmxx();
        String admagSelected = stationDao.getObitcdById(stcd);
        List<CheckBox> checkBoxes = new ArrayList<CheckBox>();
        for(Ssxmxx s : ssxmxx){
            CheckBox cb = new CheckBox();
            cb.setBoxLabel(s.getObitnm());
            cb.setInputValue(s.getObitcd());
            for(int i=0; i<admagSelected.length();i++){
                if(s.getObitcd().equals(admagSelected.substring(i,i+1))){
                    cb.setChecked(true);
                }
            }
            checkBoxes.add(cb);
        }
        return checkBoxes;
    }

    //Lskzmdygx处理
    public DataTable<LskzmdygxShow> getDataTableLskzmdygx(int draw, int start, int limit) {
        List<Lskzmdygx> list = lskzmdygxDao.getPageLskzmdygx(start, limit);
        List<LskzmdygxShow> llist = new ArrayList<LskzmdygxShow>();
        fill_Lskzmdygx(list,llist);
        DataTable<LskzmdygxShow> dt = new DataTable<LskzmdygxShow>();
        dt.setRecordsTotal(lskzmdygxDao.getLskzmdygxCount());
        dt.setRecordsFiltered(lskzmdygxDao.getLskzmdygxCount());
        dt.setDraw(draw);
        dt.setData(llist);
        return dt;
    }

    public DataTable<LskzmdygxShow> getDataTableLskzmdygxByNmOrId(int draw, int start, int limit, String nmOrid) {
        List<Lskzmdygx> list = lskzmdygxDao.getAllLskzmdygxByNmOrId(start,limit,nmOrid);
        List<LskzmdygxShow> list_show = new ArrayList<LskzmdygxShow>();
        fill_Lskzmdygx(list,list_show);
        DataTable<LskzmdygxShow> dt = new DataTable<LskzmdygxShow>();
        dt.setRecordsTotal(lskzmdygxDao.getLskzmdygxCountByNmOrId(nmOrid));
        dt.setRecordsFiltered(lskzmdygxDao.getLskzmdygxCountByNmOrId(nmOrid));
        dt.setDraw(draw);
        dt.setData(list_show);
        return dt;
    }
    public DataTable<LskzmdygxShow> getDataTableLskzmdygxByGldw(int draw, int start, int limit,String admagcd){
        List<Lskzmdygx> list = lskzmdygxDao.getPageLskzmdygxByGldw(start, limit,admagcd);
        List<LskzmdygxShow> llist = new ArrayList<LskzmdygxShow>();
        fill_Lskzmdygx(list,llist);
        DataTable<LskzmdygxShow> dt = new DataTable<LskzmdygxShow>();
        dt.setRecordsTotal(lskzmdygxDao.getLskzmdygxCountByGldw(admagcd));
        dt.setRecordsFiltered(lskzmdygxDao.getLskzmdygxCountByGldw(admagcd));
        dt.setDraw(draw);
        dt.setData(llist);
        return dt;
    }

    public DataTable<LskzmdygxShow> getDataTableLskzmdygxByAddvcd(int draw, int start, int limit,String nodeId){
        List<Lskzmdygx> list = lskzmdygxDao.getPageLskzmdygxByAddvcd(start, limit,nodeId);
        List<LskzmdygxShow> llist = new ArrayList<LskzmdygxShow>();
        fill_Lskzmdygx(list,llist);
        DataTable<LskzmdygxShow> dt = new DataTable<LskzmdygxShow>();
        dt.setRecordsTotal(lskzmdygxDao.getLskzmdygxCountByAddvcd(nodeId));
        dt.setRecordsFiltered(lskzmdygxDao.getLskzmdygxCountByAddvcd(nodeId));
        dt.setDraw(draw);
        dt.setData(llist);
        return dt;
    }

    public int addLskzmdygx(Lskzmdygx h) {
        return lskzmdygxDao.addLskzmdygx(h);
    }

    public int upptLskzmdygx(Lskzmdygx h) {
        return lskzmdygxDao.upptLskzmdygx(h);
    }

    public int deleLskzmdygx(String stcd) {
        return lskzmdygxDao.deleLskzmdygx(stcd);
    }

    public LskzmdygxShow getLskzmadygxById(String stcd){
        Lskzmdygx lskzmdygx = lskzmdygxDao.getLskzmdygx(stcd);
        LskzmdygxShow lskzmdygxShow = new LskzmdygxShow(lskzmdygx,stationDao.getStation(lskzmdygx.getStcd()).getStnm());
        return lskzmdygxShow;
    }

    //分断面处理
    public Page<Fdm> getAllFdm(String stcd){
        String pre_stcd = StcdUtils.getPureStcd(stcd);
        List<Lskzmdygx> list = lskzmdygxDao.getFdm(pre_stcd);
        List<LskzmdygxShow> llist = new ArrayList<LskzmdygxShow>();
        fill_Lskzmdygx(list,llist);
        int count = lskzmdygxDao.getFdmCount(pre_stcd);

        List<Fdm> ll = new ArrayList<Fdm>();
        for(LskzmdygxShow ls :llist){
            Fdm f = new Fdm(ls.getStcd().substring(10,12),ls.getStnm(),ls.getSwswcd());
            ll.add(f);
        }
        Page<Fdm> page = new Page<Fdm>(count+"",ll);
        return page;
    }

    public int addFdm(Fdm h,String stcd) {
        //两个表增加 一个是首页的增加 一个历史库的增加
        Station station= stationDao.getStation(stcd);
        String fdmstcd =  StcdUtils.getPureStcd(stcd)+"."+h.getFdmid();
        station.setStcd(fdmstcd);
        station.setStnm(h.getFdmnm());

        Lskzmdygx ls = new Lskzmdygx(fdmstcd,h.getFdmcd(),"","","");

        int i = lskzmdygxDao.addLskzmdygx(ls);
        int j = stationDao.addStation(station);
        return i+j;
    }

    public int upptFdm(Fdm h,String stcd) {
        //两个表更新 一个是首页的更新 一个历史库的更新
        //TODO 在首页表更新的时候要注意分段面的更新！
        Station station= stationDao.getStation(stcd);

        String fdmstcd =  StcdUtils.getPureStcd(stcd)+"."+h.getFdmid();
        station.setStcd(fdmstcd);
        station.setStnm(h.getFdmnm());

        Lskzmdygx ls = new Lskzmdygx(fdmstcd,h.getFdmcd(),"","","");

        int i = lskzmdygxDao.upptLskzmdygx(ls);
        int j = stationDao.upptStation(station);

        return i+j;
    }

    public int deleFdm(String stcd) {
        //两个表的删除 一个是首页的删除 一个历史库的删除
        int i = lskzmdygxDao.deleLskzmdygx(stcd);
        int j = stationDao.deleStation(stcd);


        return i+j;
    }

    public int checkFdm(String fdmid, String stcd) {
        String fdmstcd =  StcdUtils.getPureStcd(stcd)+"."+fdmid;
        if(lskzmdygxDao.getLskzmdygx(fdmstcd)==null){
            return 0;
        }else {

            return 1;
        }
    }

    //Czglgx处理
    public DataTable<CzglgxShow> getDataTableCzglgx(int draw, int start, int limit){
        List<Czglgx> list = czglgxDao.getPageCzglgx(start,limit);
        List<CzglgxShow> llist = new ArrayList<CzglgxShow>();
        fill_Czglgx(list,llist);
        DataTable<CzglgxShow> dt = new DataTable<CzglgxShow>();
        dt.setRecordsTotal(czglgxDao.getCzglgxCount());
        dt.setRecordsFiltered(czglgxDao.getCzglgxCount());
        dt.setDraw(draw);
        dt.setData(llist);
        return dt;
    }

    public DataTable<CzglgxShow> getDataTableCzglgxByNmOrId(int draw, int start, int limit,String nmOrId){
        List<Czglgx> list = czglgxDao.getAllCzglgxByNmOrId(start,limit,nmOrId);
        List<CzglgxShow> llist = new ArrayList<CzglgxShow>();
        fill_Czglgx(list,llist);
        DataTable<CzglgxShow> dt = new DataTable<CzglgxShow>();
        dt.setRecordsTotal(czglgxDao.getAllCzglgxCountByNmOrId(nmOrId));
        dt.setRecordsFiltered(czglgxDao.getAllCzglgxCountByNmOrId(nmOrId));
        dt.setDraw(draw);
        dt.setData(llist);
        return dt;
    }

    public int addCzglgx(Czglgx czglgx){
        return czglgxDao.addCzglgx(czglgx);
    }

    public int upptCzglgx(Czglgx czglgx){
        return czglgxDao.upptCzglgx(czglgx);
    }

    public int delCzglgx(String stcd,String pstcd){
        return czglgxDao.deleCzglgx(stcd,pstcd);
    }

    public CzglgxShow getCzglgxById(String stcd,String pstcd){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Czglgx czglgx = czglgxDao.getCzglgx(stcd,pstcd);
        CzglgxShow czglgxShow = new CzglgxShow(czglgx,stationDao.getStation(czglgx.getStcd()).getStnm(),stationDao.getStation(czglgx.getPstcd()).getStnm(),czglgx.getFrdt()==null?"":sdf.format(czglgx.getFrdt()),relationDao.getRelation(czglgx.getRela()).getRelanm());
        return czglgxShow;
    }

    public Page<CzglgxShow> getAllCzglgx(String stcd) {
        List<Czglgx> list = czglgxDao.getAllCzglgxById(stcd);
        List<CzglgxShow> llist = new ArrayList<CzglgxShow>();
        fill_Czglgx(list,llist);
        int count = czglgxDao.getAllCzglgxByIdCount(stcd);
        Page<CzglgxShow> page = new Page<CzglgxShow>(count+"",llist);
        return page;
    }

    public int getCzglgxSame(String stcd,String pstcd){
        return czglgxDao.getIfExist(stcd,pstcd);
    }

    //该方法的作用是 将查询出来的station 进行前台页面上的处理，封装到list_show中去
    private void fill(List<Station> list, List<StationShow> list_show) {
        StationShow ss = null;
        for(Station s :list){
//            System.out.println();
            //FIXME 这边还是可能会出现空值找不到的情况！跟那边后台那边一样的处理方式
            ss = new StationShow(s,
                    s.getStgrdcd()==null||s.getStgrdcd().equals("")?"":czdjxxDao.getCzdjxx(s.getStgrdcd()).getStgrd(),
                    s.getStclcd()==null||s.getStclcd().equals("")?"":czflxxDao.getCzflxx(s.getStclcd()).getStcl(),
                    s.getSttpcd()==null||s.getSttpcd().equals("")?"":czlxxxDao.getCzlxxx(s.getSttpcd()).getSttp(),
                    s.getAdmagcd()==null||s.getAdmagcd().equals("")?"":gldwDao.getGldw(s.getAdmagcd()).getAdmag(),
                    s.getRvcd()==null||s.getRvcd().equals("")?"":hlxxDao.getHlxx(s.getRvcd()).getRvnm(),
                    s.getBscd()==null||s.getBscd().equals("")?"":lyxxDao.getLymc(s.getBscd()).getBsnm(),
                    "",//多个测验项目要拆分
                    s.getHncd()==null||s.getHncd().equals("")?"":sxxxDao.getSxxx(s.getHncd()).getHnnm(),
                    s.getAddvcd()==null||s.getAddvcd().equals("")?"":xzqhxxDao.getXzqhxx(s.getAddvcd()).getAddvnm()
            );
            if(s.getObitcd()!=null&&!s.getObitcd().equals("")){
                String obitcd = s.getObitcd();
                String res = "";
                for(int i=0;i<obitcd.length();i++){
                    res = res + ssxmxxDao.getSsxmxx(obitcd.charAt(i)+"").getObitnm()+"、";
                }
                ss.setObitnm(res.substring(0,res.length()-1));
            }
            list_show.add(ss);
        }
    }

    private void fill_Lskzmdygx(List<Lskzmdygx> list, List<LskzmdygxShow> list_show) {
        LskzmdygxShow ls = null;
        for(Lskzmdygx l :list){
            ls = new LskzmdygxShow(l,stationDao.getStation(l.getStcd()).getStnm());
            list_show.add(ls);
        }
    }

    private void fill_Czglgx(List<Czglgx> list, List<CzglgxShow> list_show) {
        CzglgxShow cs = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for(Czglgx c :list){
            cs = new CzglgxShow(c,stationDao.getStation(c.getStcd()).getStnm(),stationDao.getStation(c.getPstcd()).getStnm(),c.getFrdt()==null?"":sdf.format(c.getFrdt()),relationDao.getRelation(c.getRela()).getRelanm());
            list_show.add(cs);
        }
    }
    private void fill_Sskzmdygx(List<Sskzmdygx> list, List<SskzmdygxShow> list_show) {
        SskzmdygxShow ss = null;
        Station station =null;
        Mlx mlx = null;
        Ssxmxx ssxmxx = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        for(Sskzmdygx s :list){
//            System.out.println(s);
//            System.out.println(stationDao.getStation(s.getStcd()));
//            System.out.println(mlxDao.getMlx(s.getTycd()));
//            System.out.println(ssxmxxDao.getSsxmxx(s.getObitcd()));
            ss = new SskzmdygxShow(s,
                    (station = stationDao.getStation(s.getStcd()))==null?"":station.getStnm(),
                    (mlx =mlxDao.getMlx(s.getTycd()))==null?"":mlx.getTynm(),
                    (ssxmxx = ssxmxxDao.getSsxmxx(s.getObitcd()))==null?"":ssxmxx.getObitnm(),
                    (s.getFrdt()==null?"":sdf.format(s.getFrdt())),
                    (s.getFirst_flag())
            );
            list_show.add(ss);
        }
    }

    public DataTable<SskzmdygxShow> getDataTableSskzmdygx(int draw, int start, int limit) {
        List<Sskzmdygx> list = sskzmdygxDao.getPageSskzmdygx(start, limit);
        List<SskzmdygxShow> llist = new ArrayList<SskzmdygxShow>();
        fill_Sskzmdygx(list,llist);
        DataTable<SskzmdygxShow> dt = new DataTable<SskzmdygxShow>();
        dt.setRecordsTotal(sskzmdygxDao.getSskzmdygxCount());
        dt.setRecordsFiltered(sskzmdygxDao.getSskzmdygxCount());
        dt.setDraw(draw);
        dt.setData(llist);
        return dt;
    }

    public DataTable<SskzmdygxShow> getDataTableSskzmdygxByGldw(int draw, int start, int limit,String admagcd){
        List<Sskzmdygx> list = sskzmdygxDao.getPageSskzmdygxByGldw(start,limit,admagcd);
        List<SskzmdygxShow> llist = new ArrayList<SskzmdygxShow>();
        fill_Sskzmdygx(list,llist);
        DataTable<SskzmdygxShow> dt = new DataTable<SskzmdygxShow>();
        dt.setRecordsTotal(sskzmdygxDao.getSskzmdygxByGldwCount(admagcd));
        dt.setRecordsFiltered(sskzmdygxDao.getSskzmdygxByGldwCount(admagcd));
        dt.setDraw(draw);
        dt.setData(llist);
        return dt;
    }

    public DataTable<SskzmdygxShow> getDataTableSskzmdygxByAddvcd(int draw, int start, int limit,String addvcd){
        List<Sskzmdygx> list = sskzmdygxDao.getPageSskzmdygxByAddvcd(start,limit,addvcd);
        List<SskzmdygxShow> llist = new ArrayList<SskzmdygxShow>();
        fill_Sskzmdygx(list,llist);
        DataTable<SskzmdygxShow> dt = new DataTable<SskzmdygxShow>();
        dt.setRecordsTotal(sskzmdygxDao.getSskzmdygxByAddvcdCount(addvcd));
        dt.setRecordsFiltered(sskzmdygxDao.getSskzmdygxByAddvcdCount(addvcd));
        dt.setDraw(draw);
        dt.setData(llist);
        return dt;
    }

    public DataTable<SskzmdygxShow> getDataTableSskzmdygxByNm(int draw, int start, int limit, String nmOrid) {
        List<Sskzmdygx> list = sskzmdygxDao.getAllSskzmdygxByNmOrId(start, limit,nmOrid);
        List<SskzmdygxShow> list_show = new ArrayList<SskzmdygxShow>();
        fill_Sskzmdygx(list,list_show);
        DataTable<SskzmdygxShow> dt = new DataTable<SskzmdygxShow>();
        dt.setRecordsTotal(sskzmdygxDao.getSskzmdygxCountByNmOrId(nmOrid));
        dt.setRecordsFiltered(sskzmdygxDao.getSskzmdygxCountByNmOrId(nmOrid));
        dt.setDraw(draw);
        dt.setData(list_show);
        return dt;
    }

    public SskzmdygxShow getSskzmdygxById(String stcd,String tycd,String obitcd){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Sskzmdygx sskzmdygx = sskzmdygxDao.getSskzmdygx(stcd,tycd,obitcd);
        SskzmdygxShow sskzmdygxShow = new SskzmdygxShow(sskzmdygx,
                stationDao.getStation(sskzmdygx.getStcd()).getStnm(),
                mlxDao.getMlx(sskzmdygx.getTycd()).getTynm(),
                ssxmxxDao.getSsxmxx(sskzmdygx.getObitcd()).getObitnm(),
                sskzmdygx.getFrdt()==null?"":sdf.format(sskzmdygx.getFrdt()),
                (sskzmdygx.getFirst_flag().equals("1")?"是":"")

        );
        return sskzmdygxShow;
    }

    public int addSskzmdygx(Sskzmdygx h) {
        return sskzmdygxDao.addSskzmdygx(h);
    }

    public int upptSskzmdygx(Sskzmdygx h) {
        return sskzmdygxDao.upptSskzmdygx(h);
    }

    public int deleSskzmdygx(String stcd, String tycd, String obitcd) {
        return sskzmdygxDao.deleSskzmdygx(stcd, tycd, obitcd);
    }

    public int getSame(String sscd) {
        return sskzmdygxDao.getSame(sscd);
    }

    public Page<SskzmdygxShow> getAllSskzm(String stcd) {
        List<Sskzmdygx> list = sskzmdygxDao.getAllSskzm(stcd);
        List<SskzmdygxShow> llist = new ArrayList<SskzmdygxShow>();
        fill_Sskzmdygx(list,llist);
        int count = sskzmdygxDao.getAllSskzmCount(stcd);
        Page<SskzmdygxShow> page = new Page<SskzmdygxShow>(count+"",llist);
        return page;
    }
}
